import unittest,ddt,re,random
from finance.util.read_data import ReadExcel
from finance.common.login import login
excel=ReadExcel()
@ddt.ddt
class ReviseTurnover(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print('start')
        cls.session=login()
        query=cls.session.post(url="http://192.168.2.155:8080/WoniuBoss2.5/finance/financeSelectSome",
                         data={"pageSize":"15","pageIndex":"1","subject_1":"主营业务收入",
                               "subject_2":"就业培训","selectTimeStart":"2019-01-01","selectTimeEnd":"2019-01-31"})
        text=query.text
        list=re.findall(r'"detailed_id":(.*?),',text,re.M)
        max=len(list)
        cls.did=list[random.randrange(0,max)]
        print(cls.did)

        #print(list)

    @classmethod
    def tearDownClass(cls):
        print('stop')

    @ddt.data(*excel.excel(r"E:\python\finance\data\data.xlsx",1))
    def testRevise(self,data):
        #print(data)
        result=self.session.post(url="http://192.168.2.155:8080/WoniuBoss2.5/finance/updateFinance",
                       data={ "deal.detailed_id":self.did,"deal.first_subject_id":data['deal.first_subject_id'],"deal.second_subject_id":data['deal.second_subject_id'],"deal.dealings_subject":data['deal.dealings_subject'],
                             "deal.dealings_subject1":data['deal.dealings_subject1'],"deal.trading_time":data['deal.trading_time'],"deal.person_in_charge":data['deal.person_in_charge'],
                             "income_and_expenses":data['income_and_expenses'],"deal.money_no":data['deal.money_no'],"deal.trading_account":data['deal.trading_account'],
                             "deal.counterparty":data['deal.counterparty'],"deal.detail_record":data['deal.detail_record']})
        text=result.text
        self.assertIn("成功",text)